(function(global, factory) {
	typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
		typeof define === 'function' && define.amd ? define(factory) :
		(global = global || self, global.Swiper = factory());
}(this, function() {
	'use strict';
	return function(obj) {
		if (!obj.el) {
			throw new Error('必须有el属性才能执行');
		}
		if (!obj.data) {
			throw new Error('必须有data属性才能执行');
		}
		let parentNode = document.querySelector(obj.el);
		let boundSwiper = document.createElement('div');
		boundSwiper.classList.add('da-swiper');
		parentNode.appendChild(boundSwiper);
		let boxSwiper = document.createElement('div');
		boxSwiper.style.width = parentNode.offsetWidth * obj.data.length + "px";
		boxSwiper.classList.add('da-pages-bound');
		boundSwiper.appendChild(boxSwiper);
		let progress = document.createElement('div');
		progress.classList.add('da-progress');
		boundSwiper.appendChild(progress);
		let uls = document.createElement('ul');
		progress.appendChild(uls);
		obj.data.forEach(function(item) {
			let imgHref = document.createElement('a');
			imgHref.style.width = parentNode.offsetWidth + "px";
			boxSwiper.appendChild(imgHref);
			if (item.url) {
				imgHref.href = item.url;
			}
			let imgSwiper = document.createElement('div');
			imgSwiper.style.backgroundImage = "url(" + item.src + ")";
			imgHref.appendChild(imgSwiper);
			let lis = document.createElement('li');
			uls.appendChild(lis);
		});
		let index = 0;
		let speed = 3000;
		uls.children[index].classList.add('active');
		if (obj.speed) {
			speed = obj.speed;
		}
		if (obj.transition) {
			boxSwiper.style.transitionDuration = obj.transition + "s";
		}
		let clearLis = function() {
			for (let i = 0; i < uls.children.length; i++) {
				if (uls.children[i].className.indexOf('active') !== -1) {
					uls.children[i].classList.remove('active');
				}
			}
		}
		let handle = setInterval(function() {
			boxSwiper.style.left = -index * parentNode.offsetWidth + "px";
			clearLis();
			uls.children[index].classList.add('active');
			index++;
			if (index === obj.data.length) {
				index = 0;
			}
		}, speed);
		let btnL = document.createElement('i');
		btnL.classList.add('da-swiper-left');
		boundSwiper.appendChild(btnL);
		let btnR = document.createElement('i');
		btnR.classList.add('da-swiper-right');
		boundSwiper.appendChild(btnR);
		btnL.addEventListener('click', function() {
			clearInterval(handle);
			index++;
			if (index === obj.data.length) {
				index = 0;
			}
			boxSwiper.style.left = -index * parentNode.offsetWidth + "px";
			handle = setInterval(function() {
				index++;
				if (index === obj.data.length) {
					index = 0;
				}
				boxSwiper.style.left = -index * parentNode.offsetWidth + "px";
				clearLis();
				uls.children[index].classList.add('active');
			}, speed);
		});
		btnR.addEventListener('click', function() {
			clearInterval(handle);
			index--;
			if (index === -1) {
				index = obj.data.length - 1;
			}
			boxSwiper.style.left = -index * parentNode.offsetWidth + "px";
			handle = setInterval(function() {
				index++;
				if (index === obj.data.length) {
					index = 0;
				}
				boxSwiper.style.left = -index * parentNode.offsetWidth + "px";
				clearLis();
				uls.children[index].classList.add('active');
			}, speed);
		});
	}
}));
